package kr.saeildamil.androidforstudy2.ch2930;

import kr.saeildamil.androidforstudy2.R;
import android.app.Activity;
import android.app.Notification;
import android.app.Notification.Builder;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class NapAlarm extends Activity {
	static final int NAPNOTI = 1;
	NotificationManager mNotification;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch29_napalarm);

		mNotification = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

	}

	public void mOnClick(View v) {
		Toast.makeText(this, "Good Night!", Toast.LENGTH_SHORT).show();
		v.postDelayed(new Runnable() {

			@Override
			public void run() {
				Intent intent = new Intent(NapAlarm.this, NapEnd.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				// FLAG_NEW_TASK, Must do!
				PendingIntent content = PendingIntent.getActivity(
						NapAlarm.this, 0, intent, 0);

				Notification.Builder notification = new Notification.Builder(NapAlarm.this)
						.setTicker("Wake up!")
						.setContentTitle("It's time to wake up!")
						.setContentText("Or You'll be late AGAIN!")
						.setSmallIcon(R.drawable.mugung)
						.setLargeIcon(
								BitmapFactory.decodeResource(getResources(),
										R.drawable.babydrum1))
						.setContentIntent(content);

				mNotification.notify(NAPNOTI, notification.getNotification());
			}
		}, 5 * 1000);
	}

}
